﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using System.Data;
using Newtonsoft.Json.Linq;

namespace Test_API
{
    class EmailTest : AnnouncementTest
    {
        protected override string moduleName
        {
            get
            {
                return "Email Test";
            }
        }

        public EmailTest(string accessToken, string cid)
            : base(accessToken, cid)
        {
            this.viewAllMethod = "viewAllEmails";
            this.viewSingleItemMethod = "viewEmail";
            this.addMethod = "addEmail";
            this.deleteMethod = "deleteEmail";
            this.cid = cid;
            this.uploadMethod = "uploadInEmail";
        }

        protected override string genericQueryStringGenerate(int testId)
        {
            string queryString = new Dictionary<string, string>() { { "cid", this.cid }, { "accesstoken", this.accesstoken }, { "itemid", testId.ToString() } }.buildQueryString();

            return queryString;
        }
        protected override Dictionary<string, object> genericPostDataSetGenerate()
        {
            Dictionary<string, object> dataSet = new Dictionary<string, object>();
            {
                dataSet.Add("recipients", "managers;students");
                dataSet.Add("cc", "administrator@example.rwth-aachen.de");
                dataSet.Add("body", Library.getDescription());
                dataSet.Add("subject", Library.getTitle());
            }
            return dataSet;
        }
        
        public new List<LogEntry> start(string localFile)
        {
            Console.WriteLine("Email API call begin\n============");
            List<LogEntry> entries = new List<LogEntry>();

            entries.AddRange(this.uploadFile(localFile, 5, this.uploadMethod));
            entries.AddRange(this.addOrUpdate(true));
            entries.AddRange(this.viewAll());
            entries.AddRange(this.viewSingle());
            entries.AddRange(this.delete());
           
            return entries;
        }
    }
}
